package com.jctrip.hotel.source.xxl.hmein;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jctrip.hotel.common.constant.XxlJobNameConstant;
import com.jctrip.hotel.common.util.JsonUtil;
import com.jctrip.hotel.domain.dao.HtSourceInfoDao;
import com.jctrip.hotel.domain.entity.HtSourceInfo;
import com.jctrip.hotel.source.model.CommonJobParam;
import com.jctrip.hotel.source.service.hmein.HmeinTaskService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author：Haruhi
 * @description:
 * @Date：2023/11/2 10:37
 * @Package：com.jctrip.hotel.source.xxl.hmein
 * @Project：hotel-main
 */
@Component
@Slf4j
public class SyncHmeinPicTaskPopXxlJob extends IJobHandler {
    @Autowired
    private HmeinTaskService hmeinTaskService;

    @Autowired
    private HtSourceInfoDao htSourceInfoDao;
    @Override
    @XxlJob(XxlJobNameConstant.SYNC_HMEIN_PIC_TASK_POP)
    public void execute() throws Exception {
        XxlJobHelper.log(XxlJobNameConstant.SYNC_HMEIN_PIC_TASK_POP + "xxl job start");
        try {
            CommonJobParam commonJobParam = JsonUtil.toObject(CommonJobParam.class,XxlJobHelper.getJobParam());
            HtSourceInfo htSourceInfo = htSourceInfoDao.selectOne(new LambdaQueryWrapper<HtSourceInfo>()
                    .eq(HtSourceInfo::getSourceId, commonJobParam.getSourceId()));
            if (htSourceInfo == null) {
                return;
            }
            hmeinTaskService.syncHmeinPicPop(htSourceInfo.getSourceAppId());
        } catch (Exception e) {
            log.error(XxlJobNameConstant.SYNC_HMEIN_PIC_TASK_POP + " error " ,e);
        }
        XxlJobHelper.log(XxlJobNameConstant.SYNC_HMEIN_PIC_TASK_POP + "xxl job end");
    }
}
